﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataValidateAttribute
{
    /// <summary>
    /// 所有验证类特性的父类，所有的用于验证的特性都将继承此类
    /// </summary>
    /*
     AttributeTargets.Parameter 标识该特性作用于 方法的参数
     Inherited = true  标识该特性可以被继承
     AllowMultiple = true 标识可以多次标注
         */
    [AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = true)]
    public abstract class ValidateAttribute
        : Attribute
    {
        public ValidateAttribute()
        {

        }
        public ValidateAttribute(string msg)
        {
            this.Message = msg;
        }

        /// <summary>
        /// 被验证的参数名称
        /// </summary>
        private string _argumentName;

        /// <summary>
        /// 抛出错误的信息
        /// </summary>
        private string _message;

        /// <summary>
        /// 获取被验证的参数名称
        /// </summary>
        public string ArgumentName
        {
            set
            {
                _argumentName = value;
            }
            protected get
            {
                return _argumentName;
            }
        }

        /// <summary>
        /// 异常的提示信息
        /// </summary>
        public string Message
        {
            protected get
            {
                return _message;
            }

            set
            {
                _message = value;
            }
        }

        /// <summary>
        /// 验证该值是否符合指定的规则
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public abstract void IsValidation(object value);

    }
}
